<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |
// | http://www.zen-cart.com/index.php                                    |
// |                                                                      |
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | license@zen-cart.com so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: tpl_categories_list_box.php 277 2004-29-10 
//
  $content = "";
    $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";

  for ($i=0;$i<sizeof($box_categories_array);$i++) {
	 
	 //set selected style ($box_categories_array[$i]['current'] does not work)	
	 $div_class='';
	 if ($products_id){
		 if (($products_id)&&($box_categories_array[$i]['products_id']==$products_id)){
			 $div_class='category-subs-selected';
		 }
	 }else{
		 if(($current_category_id!=0)&&($box_categories_array[$i]['category_id']==$current_category_id)){
			 $div_class='category-subs-selected';
		 }
	 }	 	 	
	
	// set top style
	if ($box_categories_array[$i]['top'] == 'true'){	
		$a_class = 'category-top';
	}elseif($box_categories_array[$i]['has_sub_cat']){
		$a_class = 'category-subs';
	}else{
		$a_class='category-products';
	}
	 // link to cat or prod
	if ($box_categories_array[$i]['is_product'] == true){
		$link = zen_href_link(FILENAME_PRODUCT_INFO, $box_categories_array[$i]['path']);
	}else{
		$link = zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']);
	}	
	//indent
	if($box_categories_array[$i]['is_product'] == true){
		$indent = str_repeat(CATEGORIES_SUBCATEGORIES_INDENT,  $box_categories_array[$i]['level']+1); 
	}else{
		$indent = str_repeat(CATEGORIES_SUBCATEGORIES_INDENT,  $box_categories_array[$i]['level']); 
	}
	//cat sub seperator
	if (($box_categories_array[$i]['level'] == 0)&&($box_categories_array[$i]['is_product'] == false)){
		$separator = '';
	}else{
		$separator = CATEGORIES_SEPARATOR_SUBS;
	}
	// count
	$count='';
	if (SHOW_COUNTS == 'true') {
		if($box_categories_array[$i]['is_product'] != true){
			$count = CATEGORIES_SEPARATOR.CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX ;
		}
	}
	//add content
	$content .= '<span class="'. $div_class .'">'. 
		$indent.$separator.'<a class="'. $a_class .'" href="'. $link .'">'. $box_categories_array[$i]['name'] .'</a>'. $count .
	'</span><br />';
	
  }


  if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true' or SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
// display a separator between categories and links
    if (SHOW_CATEGORIES_SEPARATOR_LINK == '1') {
      $content .= '<hr id="catBoxDivider" />' . "\n";
    }
    if (SHOW_CATEGORIES_BOX_SPECIALS == 'true') {
      $show_this = $db->Execute("select s.products_id from " . TABLE_SPECIALS . " s where s.status= '1' limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_SPECIALS) . '">' . CATEGORIES_BOX_HEADING_SPECIALS . '</a>' . '<br />';
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') {
      switch (true) {
        case (SHOW_NEW_PRODUCTS_LIMIT == '0'):
          $display_limit = '';
          break;
        case (SHOW_NEW_PRODUCTS_LIMIT == '1'):
          $display_limit = " and date_format(p.products_date_added, '%Y%m') >= date_format(now(), '%Y%m')";
          break;
        case (SHOW_NEW_PRODUCTS_LIMIT == '30'):
          $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 30';
          break;
        case (SHOW_NEW_PRODUCTS_LIMIT == '60'):
          $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 60';
          break;
        case (SHOW_NEW_PRODUCTS_LIMIT == '90'):
          $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 90';
          break;
        case (SHOW_NEW_PRODUCTS_LIMIT == '120'):
          $display_limit = ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 120';
          break;
      }

      $show_this = $db->Execute("select p.products_id
                                 from " . TABLE_PRODUCTS . " p
                                 where p.products_status = '1' " . $display_limit . " limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_NEW) . '">' . CATEGORIES_BOX_HEADING_WHATS_NEW . '</a>' . '<br />';
      }
    }
    if (SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true') {
      $show_this = $db->Execute("select products_id from " . TABLE_FEATURED . " where status= '1' limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' . CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS . '</a>' . '<br />';
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
      $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_ALL) . '">' . CATEGORIES_BOX_HEADING_PRODUCTS_ALL . '</a>';
    }
  }
    $content .= '</div>';

?>